import getProp from './prop'
import { validateRequired } from '../rules/utils'

const TIPS_SELECT = '选择'
/**
 * 获取验证字段
 * @param {*} { fields }
 * @return {*} rule
 */
function _getRules ({ fields }) {
  const { label, required } = getProp({ fields })
  const { verification } = fields
  const { type } = verification

  return {
    rules: [
      validateRequired(type, required, `请${TIPS_SELECT}${label}！`),
    ],
  }
}

/**
 * @export 获取select类型表单属性
 * @param {*} { fields }
 * @return {*} prop
 */
export default function getSelectProp ({ fields }) {
  const {
    choice,
    defaultProps,
  } = fields

  const rules = _getRules({ fields })

  const prop = getProp({ fields })

  return {
    ...prop,
    defaultProps,
    choice,
    ...rules,
  }
}
